import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Inject, Post, Get, Query } from '@midwayjs/core';
import { GameLevelInfoEntity } from '../../entity/info';
import { GameLevelInfoService } from '../../service/info';

/**
 * game模块-关卡信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: GameLevelInfoEntity,
  service: GameLevelInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['name'],
    fieldEq: ['type', 'difficulty', 'status', 'levelNumber'],
    select: ['a.*', 'b.name as nextLevelName'],
    join: [
      {
        entity: GameLevelInfoEntity,
        alias: 'b',
        condition: 'a.nextLevel = b.id',
        type: 'leftJoin',
      }
    ],
  }
})
export class AdminGameLevelInfoController extends BaseController {
  @Inject()
  gameLevelInfoService: GameLevelInfoService;

  @Get('/getLevels', { summary: '获取关卡列表' })
  async getLevels() {
    return this.ok(await this.gameLevelInfoService.getLevels());
  }
}
